﻿Imports System.Data.SqlClient

Public Class clsKilometrosOperativos
    Private mstrVehiculo As String
    Private mdatFecha As Date
    Private mdblKilometros As Double
    Public Property Vehiculo() As String
        Get
            Return mstrVehiculo
        End Get
        Set(ByVal value As String)
            mstrVehiculo = value
        End Set
    End Property
    Public Property Fecha As Date
        Get
            Return mdatFecha
        End Get
        Set(ByVal value As Date)
            mdatFecha = value
        End Set
    End Property
    Public Property Kilometros() As Double
        Get
            Return mdblKilometros
        End Get
        Set(ByVal value As Double)
            mdblKilometros = value
        End Set
    End Property
    Public Sub New()
        mstrVehiculo = ""
        mdatFecha = Now()
        mdblKilometros = 0
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into KilometrosOperativos (" & _
                            "Vehiculo," & _
                            "Fecha," & _
                            "Kilometros)" & _
                            "VALUES (" & _
                            "@Vehiculo," & _
                            "@Fecha," & _
                            "@Kilometros)"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("Vehiculo", mstrVehiculo)
        Command.Parameters.AddWithValue("Fecha", mdatFecha)
        Command.Parameters.AddWithValue("Kilometros", mdblKilometros)

        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el registro ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub

End Class
